const state = {
  // 当前菜单栏
  isCollapse: false,
  currentMenu: null,
  tabsList: [
    {
      path: '/home',
      name: 'home',
      meta: { title: '首页'}
    }
  ]
}

const mutations = {
  selectMenu: (state, val) => {
    if (val.name !== 'home'){
      state.currentMenu =val
      let result = state.tabsList.findIndex(item => item.name === val.name)
      result === -1 ? state.tabsList.push(val) : ''
      window.localStorage.setItem('state', state)
    } else {
      state.currentMenu = null
    }
  },
  collapseMenu: state => {
    state.isCollapse = !state.isCollapse
  },
  handleClose: (state, val) => {
    let result = state.tabsList.findIndex(item => item.name === val.name)
    state.tabsList.splice(result, 1)
  },
  delAllView: (state, view) => {
    state.tabsList = view
    state.currentMenu = null
  }

}

const actions = {

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
